from configparser import ConfigParser
from faker import Faker
faker = Faker()
name=faker.name()

# 实例化对象
config = ConfigParser()
config.read('config.ini')      # 如果文件带中文了，下次读取要加utf-8编码

# 查看
"""
value = config.get("URL","dev_base_url")
value_2 = config.get("URL","sit_base_url")
value3 = config.get('DATABASE','dev_database')
value4 = config.get("NAME",'name1')
print(value)
print("sit_base_url：%s"%value_2)
print("dev_database：%s"%value3)
print("NAME值：%s"%value4)
"""

# 修改
"""
config.set('URL','dev_base_url','www.devs.com')
# 传入section节，要修改的key-value
with open('config.ini','w') as f:
    config.write(f) # 写入改动
value = config.get('URL','dev_base_url')
print(value)    # 查看有没有改掉

config.set('NAME','name1',"")
with open('config.ini','w') as f:
    config.write(f)
"""

# 删除选项
"""
config.remove_option('URL','uat_base_url')
with open('config.ini','w') as f:
    config.write(f)
"""

# 删除节
"""
config.remove_section('URL')
with open('config.ini','w') as f:
    config.write(f)
"""
"""
[config.remove_section(i) for i in ['DATABASE','URL','NAME']]
with open('config.ini','w') as f:
    config.write(f)
"""

# 查看所有节
# print(config.sections())

# 查看某个选项是否存在于节：True、False
# print(config.has_option('URL', 'sit_base_url'))
